<?php

namespace app\common\model;
use think\Db;
class Report extends \think\Model{
    protected $table='up_report';
    public static $report_business = array(
        '1'=>'流浪狗',
        '2'=>'互助',
        '3'=>'领养',
        '4'=>'寻狗',
    );
    public function relData($pageSize,$search){
        $model = self::instance();
        $where = '';
        if($search[0]==-2){
            $where['a.report_business'] = ['>',-2];
        }elseif ($search[0]>=-1){
            $where['a.report_business'] = ['=',$search[0]];
        }
        if($search[1]!=''){
            $where['uuu.user_username|uuu.user_rel_name|uuu1.user_rel_name']=['like',"%$search[1]%"];
        }
        $list = $model->alias('a')
                      ->join('up_u_user uuu','a.report_user_id = uuu.user_id','left')
                      ->join('up_u_user uuu1','a.report_cover_user_id = uuu1.user_id','left')
                      ->join('up_admin ua','a.report_handle = ua.id','left')
                      ->join('up_report_name urn', 'a.report_type = urn.report_type_id', 'left')
                      ->where($where)
                      ->field('a.*, ua.nickname, uuu.user_username, uuu.user_attestation, 
                      uuu.user_rel_name, uuu1.user_attestation as user_attestation1, 
                      uuu1.user_username as user_username1,uuu1.user_rel_name as user_rel_name1,uuu1.user_attestation as user_attestation1, urn.report_name')
                        ->order('a.report_time desc')
                      ->paginate($pageSize);
        return $list;
    }

    private static $instance;

    public static function instance()
    {
        if (!(self::$instance instanceof self)) {
            self::$instance = new self();
        }
        return self::$instance;
    }
}